package o;

import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import java.io.IOException;
import java.net.ProtocolException;
import o.fuo.d;
import okhttp3.internal.connection.RealConnection;
import okhttp3.internal.connection.StreamAllocation;

public final class fvu implements fuo {
    private final boolean ˏ;

    static final class a extends fxn {
        long ˎ;

        a(fxx o_fxx) {
            super(o_fxx);
        }

        public void ˎ(fxi o_fxi, long j) throws IOException {
            super.ˎ(o_fxi, j);
            this.ˎ += j;
        }
    }

    public fvu(boolean z) {
        this.ˏ = z;
    }

    public fvb ˎ(d dVar) throws IOException {
        fvb.d dVar2;
        fvz o_fvz = (fvz) dVar;
        fvv ʼ = o_fvz.ʼ();
        StreamAllocation ʻ = o_fvz.ʻ();
        RealConnection realConnection = (RealConnection) o_fvz.ॱ();
        fus ˊ = o_fvz.ˊ();
        long currentTimeMillis = System.currentTimeMillis();
        o_fvz.ʽ().requestHeadersStart(o_fvz.ॱॱ());
        ʼ.ˋ(ˊ);
        o_fvz.ʽ().requestHeadersEnd(o_fvz.ॱॱ(), ˊ);
        fvb.d dVar3 = null;
        if (!fvt.ˏ(ˊ.ˋ()) || ˊ.ˎ() == null) {
            dVar2 = null;
        } else {
            if ("100-continue".equalsIgnoreCase(ˊ.ˋ("Expect"))) {
                ʼ.ˊ();
                o_fvz.ʽ().responseHeadersStart(o_fvz.ॱॱ());
                dVar3 = ʼ.ˏ(true);
            }
            if (dVar3 == null) {
                o_fvz.ʽ().requestBodyStart(o_fvz.ॱॱ());
                fxx aVar = new a(ʼ.ॱ(ˊ, ˊ.ˎ().contentLength()));
                fxj ˋ = fxr.ˋ(aVar);
                ˊ.ˎ().writeTo(ˋ);
                ˋ.close();
                o_fvz.ʽ().requestBodyEnd(o_fvz.ॱॱ(), aVar.ˎ);
                dVar2 = dVar3;
            } else {
                if (!realConnection.isMultiplexed()) {
                    ʻ.noNewStreams();
                }
                dVar2 = dVar3;
            }
        }
        ʼ.ॱ();
        if (dVar2 == null) {
            o_fvz.ʽ().responseHeadersStart(o_fvz.ॱॱ());
            dVar2 = ʼ.ˏ(false);
        }
        fvb ˏ = dVar2.ˎ(ˊ).ॱ(ʻ.connection().handshake()).ॱ(currentTimeMillis).ˏ(System.currentTimeMillis()).ˏ();
        int ˊ2 = ˏ.ˊ();
        if (ˊ2 == 100) {
            ˏ = ʼ.ˏ(false).ˎ(ˊ).ॱ(ʻ.connection().handshake()).ॱ(currentTimeMillis).ˏ(System.currentTimeMillis()).ˏ();
            ˊ2 = ˏ.ˊ();
        }
        o_fvz.ʽ().responseHeadersEnd(o_fvz.ॱॱ(), ˏ);
        if (this.ˏ && ˊ2 == DialogButton.CONFIRM) {
            ˏ = ˏ.ʽ().ॱ(fvg.ॱ).ˏ();
        } else {
            ˏ = ˏ.ʽ().ॱ(ʼ.ˎ(ˏ)).ˏ();
        }
        if ("close".equalsIgnoreCase(ˏ.ॱ().ˋ("Connection")) || "close".equalsIgnoreCase(ˏ.ˋ("Connection"))) {
            ʻ.noNewStreams();
        }
        if ((ˊ2 != 204 && ˊ2 != 205) || ˏ.ᐝ().ˏ() <= 0) {
            return ˏ;
        }
        throw new ProtocolException("HTTP " + ˊ2 + " had non-zero Content-Length: " + ˏ.ᐝ().ˏ());
    }
}
